<template>
  <div class="common-layout-page">
    <div class="common-screen-group">
      <el-form label-width="100px" :inline="true" class="common-form">
          <el-form-item label="输入框">
            <el-input size="small" v-model="query.tj1" placeholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item label="下拉">
            <el-select size="small" v-model="query.xl"  placeholder="请选择" clearable>
              <el-option v-for="item in options" :key="item.label" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="small" @click="handleClickQuery" icon="el-icon-search">
              查询
            </el-button>
            <el-button size="small" @click="handleReset" icon="el-icon-refresh-right">
              重置
            </el-button>
          </el-form-item>
        </el-form>
    </div>

    <div class="common-content-group">
      <div class="common-operate-group">
        <el-button class="common-btn-group" type="primary" size="mini" icon="el-icon-plus" @click="handleAddEdit('add')">
          新增
        </el-button>
      </div>
      <div class="common-table-list-group">
        <el-table v-loading="loading" :data="tableList" border size="small"
          class="common-table-group" @selection-change="handleSelectionChange" height="100%"
        >
          <el-table-column type="selection" width="50"></el-table-column>
          <el-table-column type="index" width="50" label="序号" align="center"></el-table-column>
          <el-table-column property="qt" label="其他内容" show-overflow-tooltip align="center"></el-table-column>

          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="{ row }">
              <el-button type="text">详情</el-button>
              <el-popconfirm title="确定要删除当前项数据吗？" @confirm="handleRemoveColum(row)">
                <el-button type="text" slot="reference" style="color: #d9001d; margin-left: 8px;">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <el-pagination
        class="common-table-plagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.currentPage"
        :page-sizes="[20, 50, 100, 200]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <add-edit-dialog ref="addEditDialogRef" v-if="isShowAddEditDialog" @resref="handleResref"></add-edit-dialog>
  </div>
</template>

<script>
import AddEditDialog from './components/addEditDialog .vue';
export default {
  name: "TableTemplate",
  components:{
    AddEditDialog
  },
  data() {
    return {
      loading: false,
      query: {
        tj1: '',
        xl:"",
        currentPage: 1,
        pageSize: 20,
      },
      tableList: [{qt:"cs"}],
      total: 0,
      options:[
        {label:'全部', value: ''}
      ],

      isShowAddEditDialog: false,
    };
  },
  mounted() {
    this.initPage();
  },
  methods: {
    initPage() {
      this.loading = true;
      setTimeout(() => {
        this.loading = false;
      }, 2000);
    },
    handleClickQuery(){
      this.query.currentPage = 1
      this.query.pageSize = 20
      this.initPage()
    },
    handleReset(){
      this.query = {
        tj1: '',
        xl:"",
        currentPage: 1,
        pageSize: 20,
      }
      this.initPage()
    },
    handleSizeChange(val) {
      this.query.pageSize = val;
      this.initPage();
    },
    handleCurrentChange(val) {
      this.query.currentPage = val;
      this.initPage();
    },
    handleAddEdit(type){
      this.isShowAddEditDialog = true
      this.$nextTick(()=>{
        this.$refs['addEditDialogRef'].init({})
      })
    },
    handleSelectionChange(selectList) {},
    handleRemoveColum(row){},

    handleResref(bool){
      this.isShowAddEditDialog = false
      bool && this.initPage()
    },
  },
};
</script>

<style lang="scss" scoped>
@import url("~@/assets/scss/common-layout.scss");
</style>
